<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Object Pool Allocator: High-level (Macro) interface</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Object Pool Allocator
   &#160;<span id="projectnumber">1.3.5.1.4.1.45340.1.1.2</span>
   </div>
   <div id="projectbrief">Space-reusing dynamic allocation in C.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a>  </div>
  <div class="headertitle">
<div class="title">High-level (Macro) interface</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga1ccfddfc8243b5f14f9cabbc58d3e08a"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hlinterface.html#ga1ccfddfc8243b5f14f9cabbc58d3e08a">OP_HL_DECLARE_ALLOCATOR</a>(TYPE,  COUNT,  MODE)</td></tr>
<tr class="memdesc:ga1ccfddfc8243b5f14f9cabbc58d3e08a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Declare a component allocator.  <a href="#ga1ccfddfc8243b5f14f9cabbc58d3e08a">More...</a><br /></td></tr>
<tr class="separator:ga1ccfddfc8243b5f14f9cabbc58d3e08a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">TYPE</td><td>The type of objects to be allocated. </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">COUNT</td><td>The initial object count for the allocator. </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">MODE</td><td>The mode of the allocator (as per the low-level interface).</td></tr>
  </table>
  </dd>
</dl>
<p>The high-level interface is the intended use of this library. The focus is on a component based design where a single source file contains a single component which is allocated and deallocated dynamically, thus profiting from reuse to minimize fragmentation and increase amortized allocation speed.</p>
<p>Each use of the <code><a class="el" href="group__hlinterface.html#ga1ccfddfc8243b5f14f9cabbc58d3e08a" title="Declare a component allocator. ">OP_HL_DECLARE_ALLOCATOR()</a></code> macro creates one type-safe allocator using the starting count and mode provided. It also creates several static functions whose name invoke the given type. For example: </p><pre class="fragment">OP_HL_DECLARE_ALLOCATOR(my_fancy_type, 4, OP_DOUBLING_CHUNK);
</pre><p>This invocation results in the following static functions: </p><pre class="fragment">static inline void initialize_my_fancy_type_allocator(void);
static inline my_fancy_type *allocate_my_fancy_type(void);
static inline void deallocate_my_fancy_type(my_fancy_type *object);
static inline void deinitialize_my_fancy_type_allocator(void);
</pre><p>Low-level operations can still be used if desired, via the provided: </p><pre class="fragment">static op_allocator my_fancy_type_allocator;
</pre><p>Use of all of these is precisely the same as for the low-level interface, but the allocation and deallocation is type-safe.</p>
<dl class="section note"><dt>Note</dt><dd>There is no real need to call the initialization function because the allocation function does that automatically on first invocation.</dd>
<dd>
The deinitialization function is really only needed for obsessive clean-up. </dd></dl>
<h2 class="groupheader">Macro Definition Documentation</h2>
<a id="ga1ccfddfc8243b5f14f9cabbc58d3e08a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga1ccfddfc8243b5f14f9cabbc58d3e08a">&#9670;&nbsp;</a></span>OP_HL_DECLARE_ALLOCATOR</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define OP_HL_DECLARE_ALLOCATOR</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">TYPE, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">COUNT, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">MODE&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<b>Value:</b><div class="fragment"><div class="line"><span class="keyword">static</span> <a class="code" href="struct__op__allocator.html">op_allocator</a> TYPE##_allocator;                                         \</div><div class="line">static <span class="keywordtype">bool</span> TYPE##_allocator_initialized = <span class="keyword">false</span>;                             \</div><div class="line">static <span class="keyword">inline</span> <span class="keywordtype">void</span> initialize_##TYPE##_allocator(<span class="keywordtype">void</span>)                        \</div><div class="line">{ TYPE##_allocator = <a class="code" href="group__llinterface.html#gaf0ba071e1d766a1e7cb9ba7c40d5b4ba">op_ll_initialize_allocator</a>(<span class="keyword">sizeof</span>(TYPE), COUNT, MODE); } \</div><div class="line">static <span class="keyword">inline</span> TYPE *allocate_##TYPE(<span class="keywordtype">void</span>)                                     \</div><div class="line">{ <span class="keywordflow">if</span> (!TYPE##_allocator_initialized)                                          \</div><div class="line">  { initialize_##TYPE##_allocator(); TYPE##_allocator_initialized = <span class="keyword">true</span>; }   \</div><div class="line">  return <a class="code" href="group__llinterface.html#ga92340cf30ad310a00d2f24ac2f480156">op_ll_allocate_object</a>(TYPE##_allocator); }                           \</div><div class="line">static <span class="keyword">inline</span> <span class="keywordtype">void</span> deallocate_##TYPE(TYPE *<span class="keywordtype">object</span>)                            \</div><div class="line">{ <a class="code" href="group__llinterface.html#gac5c6703fea3c0a2e39d07f4bfac031a8">op_ll_deallocate_object</a>(TYPE##_allocator, <span class="keywordtype">object</span>); }                        \</div><div class="line">static <span class="keyword">inline</span> <span class="keywordtype">void</span> deinitialize_##TYPE##_allocator(<span class="keywordtype">void</span>)                      \</div><div class="line">{ <a class="code" href="group__llinterface.html#ga278159fc6bbfb1c2e2513530cbee0e96">op_ll_deinitialize_allocator</a>(TYPE##_allocator); }</div><div class="ttc" id="group__llinterface_html_gac5c6703fea3c0a2e39d07f4bfac031a8"><div class="ttname"><a href="group__llinterface.html#gac5c6703fea3c0a2e39d07f4bfac031a8">op_ll_deallocate_object</a></div><div class="ttdeci">void op_ll_deallocate_object(op_allocator allocator, const void *object)</div><div class="ttdoc">Deallocate a specified object from the given allocator. </div><div class="ttdef"><b>Definition:</b> opalloc.c:110</div></div>
<div class="ttc" id="group__llinterface_html_ga278159fc6bbfb1c2e2513530cbee0e96"><div class="ttname"><a href="group__llinterface.html#ga278159fc6bbfb1c2e2513530cbee0e96">op_ll_deinitialize_allocator</a></div><div class="ttdeci">void op_ll_deinitialize_allocator(op_allocator allocator)</div><div class="ttdoc">De-initialize an allocator, freeing any owned resources. </div><div class="ttdef"><b>Definition:</b> opalloc.c:129</div></div>
<div class="ttc" id="group__llinterface_html_ga92340cf30ad310a00d2f24ac2f480156"><div class="ttname"><a href="group__llinterface.html#ga92340cf30ad310a00d2f24ac2f480156">op_ll_allocate_object</a></div><div class="ttdeci">void * op_ll_allocate_object(op_allocator allocator)</div><div class="ttdoc">Allocate an object in the given allocator context. </div><div class="ttdef"><b>Definition:</b> opalloc.c:51</div></div>
<div class="ttc" id="group__llinterface_html_gaf0ba071e1d766a1e7cb9ba7c40d5b4ba"><div class="ttname"><a href="group__llinterface.html#gaf0ba071e1d766a1e7cb9ba7c40d5b4ba">op_ll_initialize_allocator</a></div><div class="ttdeci">op_allocator op_ll_initialize_allocator(const size_t object_size, const size_t initial_count, const op_ll_allocator_mode mode)</div><div class="ttdoc">Initialize an allocator according to the provided configuration. </div><div class="ttdef"><b>Definition:</b> opalloc.c:187</div></div>
<div class="ttc" id="struct__op__allocator_html"><div class="ttname"><a href="struct__op__allocator.html">_op_allocator</a></div><div class="ttdef"><b>Definition:</b> opalloc.c:36</div></div>
</div><!-- fragment -->
<p>Declare a component allocator. </p>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
